package com.ruiysoft.controller.freight;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruiysoft.entity.feight.Freight;
import com.ruiysoft.pub.core.Result;
import com.ruiysoft.pub.core.ResultGenerator;
import com.ruiysoft.service.feight.IFreightService;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2018-11-10T22:47:21.301+08:00")

@RestController
public class InnrFreightApiController implements InnrFreightApi {

    private static final Logger log = LoggerFactory.getLogger(InnrFreightApiController.class);

    private final IFreightService freightService;

    @org.springframework.beans.factory.annotation.Autowired
    public InnrFreightApiController(IFreightService freightService) {
        this.freightService = freightService;
    }

    @Override
    public Result<Long> innrFreightComputeGet(@NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "fee", required = true) Long fee, @NotNull @ApiParam(value = "", required = true) @Valid @RequestParam(value = "shopId", required = true) Long shopId) {
        try {
            Long freightFee = Long.valueOf(0);
//            Freight freight = freightService.getOne(new QueryWrapper<Freight>().eq("shop_id",shopId));
//            if(freight!=null && freight.getFee() != null){
//                Long fullFee = freight.getFullFee()==null?Long.MAX_VALUE:freight.getFullFee();
//                if(fee.compareTo(fullFee) < 0){
//                    freightFee = Long.valueOf(freight.getFee());
//                }
//            }
            return ResultGenerator.genSuccessResult(freightFee);
        } catch (Exception e) {
            log.error("innr订单查询获取运费金额--{}--{}",shopId,fee, e);
            return ResultGenerator.genFailResult(e.getMessage());
        }
    }

}
